<template>
  <div>
    {{ personList.length }}
    <h1>当前求和为:{{ num }}</h1>
    <h1>当前求和扩大10倍为:{{ bigNum }}</h1>
    <h1>我想{{ Sname }} {{ subject }}</h1>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="addN(n)">+</button>
    <button @click="minusN(n)">-</button>
    <button @click="OddNum(n)">当前求和为奇数</button>
    <button @click="delayAdd(n)">等一等再加</button>
  </div>
</template>

<script>
import { mapState ,mapGetters,mapActions,mapMutations} from "vuex";
export default {
  name: "count",
  data() {
    return {
      n: 1,
    };
  },
  computed: {
    // num(){
    //     return this.$store.state.num
    // },
    // Sname(){
    //     return this.$store.state.Sname
    // },
    // subject(){
    //     return this.$store.state.subject
    // },
    //   bigNum(){
    //     return this.$store.getters.bigNum
    // }
    //mapState对象写法
    // ...mapState({num:'num',Sname:'Sname',subject:'subject'}),
    ...mapState('countAbout',["num", "Sname", "subject"]),
    ...mapState('personAbout',["personList"]),
    ...mapGetters('countAbout',["bigNum"]),
  },
  methods: {
     ...mapMutations('countAbout',{ addN: "ADDN", minusN: "MINUSN" }),
     ...mapActions( 'countAbout',{OddNum: "addOddN", delayAdd: "addDelayN" }),
    // addN(){
    //     this.$store.commit('ADDN',this.n)
    // },
    // minusN(){
    //     this.$store.commit('MINUSN',this.n)
    // },
    // OddNum(){
    //     this.$store.dispatch('addOddN',this.n)
    // },
    // delayAdd(){
    //     this.$store.dispatch('addDelayN',this.n)
    // }
  },
  mounted() {
    // const x = mapState({num:'num',Sname:'Sname',subject:'subject'})
    // console.log(x);
  },
};
</script>

<style>
button {
  margin-left: 5px;
}
</style>